package Homework01;

public class Homework01 {
    public static void main(String[] args) {
        Person[] p = new Person[3];
        p[0] = new Person("jack", 20, "学生");
        p[1]= new Person("mary", 18, "医生");
        p[2]= new Person("tom", 13, "程序员");
        //对象数组
        //按年龄大小排序,使用冒泡排序
        //1.每一轮找一个最大的数，个数-1次，2次
        //2.内部每轮进行进行次数-1次比较
        Person temp = null;//临时变量，用于交换
        for(int i = 0; i < p.length - 1; i++){
            for(int j = 0; j < p.length - 1 - i; j++){
                if(p[j].getAge() > p[j + 1].getAge()){
                    temp = p[j];
                    p[j] = p[j + 1];
                    p[j + 1] = temp;
                }
            }
        }
        for (int i = 0; i < p.length; i++) {
            System.out.println(p[i]);
        }
    }
}
class Person{
   private String name;
   private int age;
   private String job;

    public Person(String name, int age, String job) {
        this.name = name;
        this.age = age;
        this.job = job;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", job='" + job + '\'' +
                '}';
    }
}
